
#include "unpicmp.h"

void dg_client(FILE * fp, int sockfd, const struct sockaddr * sa, socklen_t sa_len) {

    int     icmpfd, maxfdp1;
    char    sendline[MAXLINE],  recvline[MAXLINE + 1];

    fd_set rset;

    ssize_t n;
    struct timeval tv;
    struct icmpd_err icmpd_err;

    struct sockaddr_un sun;

    // 暂时用ipv4
    struct sockaddr_in sai;
    bzero(&sai, sizeof(sai));
    sai.sin_family = sa->sa_family;
    sai.sin_addr.s_addr   = htons(INADDR_ANY);
    sai.sin_port          = htons(0);
    bind(sockfd, (struct sockaddr *)&sai, sizeof(sai));

    
    icmpfd = socket(AF_LOCAL, SOCK_STREAM, 0);
    sun.sun_family = AF_LOCAL;
    strcpy(sun.sun_path, ICMP_PATH);

    if (connect(icmpfd, (struct sockaddr *)&sun, sizeof(sun)) != 0) {

        printf("connect failed and sockfd = %d and errno : %d.\n", icmpfd, errno);
        exit(1);
    }
}